package com.server;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.log4j.chainsaw.Main;



import com.base.BaseController;
import com.base.util.SpringUtils;
import com.bean.Accountmanager;
import com.bean.Useraccountinfo;
import com.bean.Userallinfo;
import com.bean.Userextendinfo;
import com.dao.AccountmanagerDao;
import com.dao.UserExtendInfoDao;
import com.dao.UseraccountinfoDao;
import com.dao.UserallinfoDao;
import com.google.gson.Gson;

public class UserDetailServlet extends BaseController {
	static Logger log = Logger.getLogger(UserDetailServlet.class);
	
	

	
	UserallinfoDao userallinfoDao;
	
	public void queryUserDetailInfo(HttpServletRequest request, HttpServletResponse response) throws IOException {
		HashMap<String,Object> retMap = new HashMap<String,Object>();
		//每页显示的个数
		String size = request.getParameter("size");
		//显示第几页
		String page = request.getParameter("page");
		
		String hql = "from Userallinfo";
		int from = (Integer.valueOf(page)-1)*Integer.valueOf(size);
		
		List<Userallinfo> list = userallinfoDao.listByHQL(hql, from, Integer.valueOf(size));
		long total = userallinfoDao.getCount(hql);
		retMap.put("total", String.valueOf(total));
		retMap.put("result", list);
		retMap.put("page", page);
		
		Gson gson = new Gson();
		String retString = gson.toJson(retMap);
		response.getWriter().print(retString);
	}

	
	public static void main(String[] args) {
		String hql = "select * from Userextendinfo u1,Useraccountinfo u2 where u1.userId = u2.userid";
		UserExtendInfoDao userExtendInfoDao = (UserExtendInfoDao) SpringUtils.getInstance().getBean("userExtendInfoDao");
		List<Object> list = userExtendInfoDao.query(hql, 0, 10);
		System.out.println(list);
	}


	public UserallinfoDao getUserallinfoDao() {
		return userallinfoDao;
	}


	public void setUserallinfoDao(UserallinfoDao userallinfoDao) {
		this.userallinfoDao = userallinfoDao;
	}
}
